<?php
namespace app\index\controller;

use think\Controller;


class Login extends Controller
{
    public function login(){
        return view();
    }
    
    public function dologin(){
        $param = input('post.');
        if(empty($param['email'])){
            $this->error('email不能为空');
        }
        $rs = db('tb_member')->where('email', $param['email'])->find();
        if(empty($rs)){
            $this->error('用户名错误');
        }
        if($rs['password'] != md5($param['passw'])){
            $this->error('密码错误');
        }
        
//         $remember = $param['rem'];
        
//         if(!empty($remember)){     //如果用户选择了，记录登录状态就把用户名和加了密的密码放到cookie里面
//             setcookie("email", $rs['email'], time()+3600*24*30);
//             setcookie("passw", $rs['password'], time()+3600*24*30);
//         }
        
        session('email',$rs['email']);
        $this->redirect(url('index/index'));
    }
    
    public function logOut(){
        session('email',null);
        $this->redirect(url('index/index'));
    }
}